package kk;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


//@WebServlet(name="hm",urlPatterns = "/hm")
public class servlet extends HttpServlet {
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        //super.doGet(request,response);
       /* ServletRequest servletRequest=request;
        HttpServletRequest requsetHttp=(HttpServletRequest)servletRequest;
        servletRequest.getLocalAddr();
        request.getContentLength();
        System.out.print("IP地址"+servletRequest.getLocalAddr());
        response.getWriter().println("IP");*/
        //doGet(request,response);
    }


    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        // super.doGet(request,response);
        //doPost(request,response);
        //设置请求值的编码方式
        /*request.setCharacterEncoding("utf-8");

        response.setCharacterEncoding("utf-8");

        String  json="{\"resultCode\":0,\"message\":\"请求成功\"，\"name\";\"zhammgsam\"}";
        response.getWriter().append(json);*/
        response.setHeader("content-type", "text/html;charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        request.setCharacterEncoding("UTF-8");
        String s=request.getParameter("username");
        response.setCharacterEncoding("utf-8");
        /*response.getWriter().append("<html><meat charset=\"utf-8\"><body>");
        response.getWriter().append("我的账号是："+s);

        response.getWriter().append("</html><body>");*/
        request.setAttribute("username",s);
       // request.getRequestDispatcher("/hello.jsp").forward(request,response);
        request.getRequestDispatcher("/servlet.jsp").forward(request, response);



    }
}
